package com.blb.exam.student.dao.impl;

import com.blb.exam.common.entity.ExamRecord;
import com.blb.exam.common.util.DBUtils;
import com.blb.exam.student.dao.ExamRecordDAO;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ExamRecordDAOImpl implements ExamRecordDAO {

    @Override
    public List<ExamRecord> selectByUserId(Long userId) {
        return DBUtils.executeQuery(ExamRecord.class,
                "select r.*,u.username,q.title quetion_set_title from t_exam_record r" +
                        " join t_quetion_set q on r.quetion_set_id = q.id" +
                        " join t_user u on r.user_id = u.id where r.user_id = ?",userId);
    }

    @Override
    public void insert(ExamRecord examRecord) {
        DBUtils.executeUpdate("insert into t_exam_record(user_id,quetion_set_id,exam_date,point) values(?,?,?,?)",
                examRecord.getUserId(),examRecord.getQuetionSetId(),examRecord.getExamDate(),examRecord.getPoint());
    }
}
